﻿using System.Collections.Generic;
using System.Web;
using System.Web.Caching;
using System.Web.Mvc;
using Business;
using Dto;

namespace YaoYunDong.Controllers
{
    public class ChannelBaseController : Controller
    {
        private readonly ChannelBusiness _channelBusiness = new ChannelBusiness();
        protected UsersDto UserInfo;
        protected Dictionary<string, SiteChannelDto> SiteChannelDictionary = new Dictionary<string, SiteChannelDto>();

        public ChannelBaseController()
        {
            var cache = HttpRuntime.Cache;
            if (cache["SiteChannel"] == null)
            {
                var channelDtos = _channelBusiness.GetShowList();
                foreach (var channelDto in channelDtos)
                {
                    SiteChannelDictionary.Add(channelDto.ChannelCode, channelDto);
                }
                cache.Insert("SiteChannel", SiteChannelDictionary);
            }
            else
            {
                SiteChannelDictionary = cache["SiteChannel"] as Dictionary<string, SiteChannelDto>;
            }

            if (System.Web.HttpContext.Current.Session != null && System.Web.HttpContext.Current.Session["User"] != null)
            {
                UserInfo = System.Web.HttpContext.Current.Session["User"] as UsersDto;
            }
        }
    }
}